package com.byzk.p2p.admin.task;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import com.byzk.p2p.admin.base.util.DateUtils;
import com.byzk.p2p.admin.money.service.FundRecordService;
import com.byzk.p2p.admin.money.util.FundRecordType;
import com.byzk.p2p.admin.user.dto.UserAccount;
import com.byzk.p2p.admin.user.service.UserAccountService;
/**
 * 自动任务:迅泊达每月1日17：00前会向钻石会员、金钻会员账户内发放待领奖金2000元
 * @author suker.zhou
 */

@Component
public class GiveOutBonus {
	@Autowired
	private UserAccountService userAccountService;
	@Autowired
	private FundRecordService fundService;
	/**
     * 定时器每月一号14:00:00向钻石会员、金钻会员发放待领奖金奖金
     */
	//@Scheduled(cron = "0 0 14 1 * ? ")
    public void taskGiveOut(){
		System.out.println("自动任务开始==============================开始时间："+DateUtils.getNowTimeString());
		List<UserAccount>  listUserAccount= userAccountService.getAccountLevel5Or6();
		int i=0;
		for(UserAccount userAccount : listUserAccount) {
			if(userAccount == null) continue;
			i++;
			if(userAccount.getLevel() == 5 || userAccount.getLevel() == 6) {//给钻石会员和金钻会员添加待领奖励   
				userAccount.setStayAmount(userAccount.getStayAmount() + 2000.0);
				userAccountService.saveOrUpdate(userAccount);
				fundService.addFundRecord(userAccount.getUserId(), 2000.0, 0.0, "PC", "钻石、金钻会员每月奖励", FundRecordType.Type.STAY_MONEY.index, 0.0);
				System.out.println("第"+i+"笔，用户["+userAccount.getUserId()+"]增加待领奖金成功");
			}
		}
		System.out.println("自动任务开始==============================结束时间："+DateUtils.getNowTimeString()+"，共"+i+"笔");
	}
}

